package top100;

/**
 * @author Godc
 * @description
 */
public class AddStrings {
    public static void main(String[] args) {
        AddStringsSolution s = new AddStringsSolution();
        String s1 = s.addStrings("11", "123");
        System.out.println(s1);
    }
}
class AddStringsSolution {
    public String addStrings(String num1, String num2) {
        StringBuffer buffer = new StringBuffer();
        int carry = 0;
        int k = Math.max(num1.length(),num2.length());
        while(k-->0){
            int a = k<num1.length()?Integer.valueOf(num1.charAt(k)-'0'):0;
            int b = k<num2.length()?Integer.valueOf(num2.charAt(k)-'0'):0;
            int sum = a+b;
            buffer.append(sum%10);
            carry = sum/10;
        }
        if(carry!=0)
            buffer.append(1);
        return buffer.reverse().toString();
    }
}